package com.wjq.demo.springmvc;

import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;

import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.Set;

/**
 * @author wjq
 * @since 2023-03-01
 */
public class StringTrimConverter implements ConditionalGenericConverter {
    @Override
    public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
        Object source = targetType.getSource();
        Object source1 = targetType.getResolvableType().getSource();
        System.out.println(source1);
        System.out.println(source);
        Annotation[] annotations = targetType.getSource().getClass().getAnnotations();
        System.out.println(annotations);
        return true;
    }

    @Override
    public Set<ConvertiblePair> getConvertibleTypes() {
        return Collections.singleton(new ConvertiblePair(String.class, String.class));
    }

    @Override
    public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
        return source;
    }
}
